﻿using System.Linq;
using System.Windows.Markup;
using System.Windows.Media;

namespace CgdataBase
{
    public static class FontController
    {
        private static FontInfo[] _items;

        public static FontInfo[] GetFontItems()
        {
            if (_items == null)
            {
                _items = Fonts.SystemFontFamilies.Select(s => new FontInfo(s)).ToArray();
            }

            return _items;
        }

        public class FontInfo
        {
            public string FontName { get; set; }
            public FontFamily FontFamily { get; set; }

            public FontInfo(FontFamily fontFamily)
            {
                FontName = GetFontName(fontFamily);
                FontFamily = fontFamily;
            }

            private string GetFontName(FontFamily font)
            {
                var lang = XmlLanguage.GetLanguage("zh-cn");
                if (font.FamilyNames.ContainsKey(lang))
                {
                    return font.FamilyNames[lang];
                }
                else
                {
                    return font.ToString();
                }
            }
        }
    }
}